import org.apache.commons.pool.PoolableObjectFactory;
import com.sap.smb.sbo.api.ICompany;

/**
 * Created by IntelliJ IDEA.
 * User: mlv
 * Date: 2013-2-22
 * Time: 15:15:00
 * To change this template use File | Settings | File Templates.
 */
public class SboPoolFactory  implements PoolableObjectFactory<ICompany> {
    private static int counter = 0;

    public ICompany makeObject() throws Exception {
        ICompany company = JcoConn.conn();
        if(company != null)
            counter++;
        System.out.println(counter);
        return company;
    }

    public void activateObject(ICompany obj) throws Exception {
    }

    public void passivateObject(ICompany obj) throws Exception {
    }

    public boolean validateObject(ICompany obj) {
        return obj.isConnected();
    }
    
    public void destroyObject(ICompany obj) throws Exception {
        obj.disconnect();
        obj.release();
    }
} 